<template>
  <div class="dialog_container" v-show="visible">
    <!-- 遮罩层 -->
    <div class="dialog_wrapper"></div>
    <div class="dialog" :style="{ width: width, height: height }">
      <div class="dialog_header">
        <slot name="title">
          <span>{{ title }}</span>
        </slot>
        <button>
          <i class="zh-iconfont zh-icon-close"></i>
        </button>
      </div>
      <div class="dialog_body">
        <slot name="content">
          <span>{{ content }}</span>
        </slot>
      </div>
      <div class="dialog_footer" v-if="$slots.footer">
        <slot name="footer"></slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  // 组件名称
  name: "zh-dialog",
  // 组件参数 接收来自父组件的数据
  props: {
    // 标题
    title: {
      type: String,
      default: "提示",
    },
    // 宽
    width: {
      type: String,
      default: "50%",
    },
    height: {
      type: String,
      default: "20%",
    },
    content: {
      type: String,
      default: "这是一段内容",
    },
    // 是否显示dialog
    visible:{
        type:Boolean,
        default:false
    },
    // 是否显示遮罩层
    modal:{
        type:Boolean,
        default:true,
    }
  },
  // 局部注册的组件
  components: {},
  // 组件状态值
  data() {
    return {};
  },
  mounted() {},
  // 计算属性
  computed: {},
  // 侦听器
  watch: {},
  // 组件方法
  methods: {},
  /**
   * 组件实例创建完成
   */
  created() {},
};
</script>

<style lang="scss" scoped>
@import "../variable";

.dialog_wrapper {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: auto;
  margin: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 999;

  &.show {
    animation: show-mask 0.3s linear forwards;
  }
}

.dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  background: $white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, -50%);
  overflow: hidden;
  z-index: 999;

  .dialog_header {
    padding: 20px 20px 10px;
    box-sizing: border-box;
    span {
      line-height: 24px;
      font-size: 18px;
      color: #303133;
    }

    button {
      position: absolute;
      top: 20px;
      right: 20px;
      background: $white;
      background: transparent;
      border: none;
      outline: none;
      cursor: pointer;
      text-align: right;
      color: #909399;
      font-size: 16px;
      &:hover {
        color: $blue;
      }
    }
  }

  .dialog_body {
    padding: 30px 20px;
    color: #606266;
    font-size: 14px;
    word-break: break-all;
  }

  .dialog_footer {
    display: flex;
    justify-content: flex-end;
    padding-right: 20px;
    box-sizing: border-box;
  }
}
</style>
